<?php
/**
 * Dirox Framework
 * Copyright (C) 2005 - 2007 Dirox / Synexser
 * 
 * All rights reserved.
 */
 
require_once 'Smarty/libs/Smarty.class.php';

class DRX_Smarty extends Smarty {

	/**
	 * Overriding of smarty fetch function to automatically load if necessary
	 * a language file which have the same name as the tpl (followed by .ini)
	 */
	function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
	{
		if (ACTIVATE_SMARTY_LANGUAGE_RESOURCE)
		{
			// Load automatically the ressource file with the same name
			if ($this->_parse_resource_name(
				$prnp = array('resource_name' => $resource_name.'.ini',
					'resource_base_path' => $this->config_dir,
					'get_source' => false)) )
			{
				$this->config_load($resource_name.'.ini',DRX_MultiLanguage::getLanguage(),'local');
			}
		}

		return parent::fetch($resource_name,$cache_id,$compile_id,$display);
	}

	function _smarty_include($params)
	{
		if (ACTIVATE_SMARTY_LANGUAGE_RESOURCE)
		{
			array_unshift($this->_config, $this->_config[0]);

			if ( $this->_parse_resource_name(
				$prnp = array('resource_name' => $params['smarty_include_tpl_file'].".ini",
					'resource_base_path' => $this->config_dir,
					'get_source' => false)) )
			{
				$this->config_load($params['smarty_include_tpl_file'].".ini",DRX_MultiLanguage::getLanguage(),'local');
			}

			parent::_smarty_include($params);

			array_shift($this->_config);
		}
		else
		{
			parent::_smarty_include($params);
		}
	}
}
?>